
"""
主页页面
1. 导航到发布话题页面
2. 打开某个话题到话题详情页面
"""
from pom.basepage import BasePage
from pom.createpage import CreatePage
from pom.topicdetailpage import DetailPage
from pom.togglepage import TogglePage

class MainPage(BasePage):

    def __init__(self,driver):
        super().__init__(driver)
        self.create_topic_btn_xpath='//*[@resource-id="org.cnodejs.android.md:id/fab_create_topic"]'
        self.__topic_xpath = '//*[@resource-id="org.cnodejs.android.md:id/btn_topic"]'
    def go_to_create_topic(self):
        """
        导航到发布话题页面
        :return:
        """
        self.driver.find_element_by_xpath(self.create_topic_btn_xpath).click()
        return CreatePage(self.driver)


    def go_to_topic_detail_page(self):
        self.driver.find_element_by_xpath(self.__topic_xpath).click()
        return DetailPage(self.driver)

    def click_toggle_btn(self):
        toggle = self.driver.find_element_by_xpath('//*[@resource-id="org.cnodejs.android.md:id/toolbar"]/android.widget.ImageButton')
        toggle.click()
        return TogglePage(self.driver)